$(document).ready(function(){
$(document).on('click', ".del", (function (){
    $(".module").css("display", "block")
    $("body").append("<div class='delete-msg'></div>")
    $(".delete-msg").append("<p></p><div><button type='submit' class='sure-del' onclick='sure()'>确定</button> " +
        "<button type='button' class='cancel-del' onclick='cancel()'>取消</button></div>")
    // $(".delete-msg>p").attr('value', $(this).closest('div').attr('id'))
    $(".delete-msg>p").text("确认删除"+$(this).closest('div').find('input:first-child').attr('value')+"用例吗？")
        .attr('id', $(this).closest('div').attr('id'))
}));

});
function cancel(){
    $("div.delete-msg").remove();
    $(".module").css("display", "none")
}
function sure(){
    let id = $(".delete-msg>p").attr("id")
    $.ajax({
        url: "/testcase/api/delete/",
        type: "post",
        data: {
            id: id
        },
        success: function (response){
            stat = response.code;
            if (stat===200){
                $("div.delete-msg").remove();
                $(".module").css("display", "none");
                $("body").append("<div class='msg'>删除成功！</div>")
                $(".msg").show().delay(1500).fadeOut();
                let modelid = $(".ismodel").attr("id").slice(5)
                $.ajax({
                    url: "/testcase/api/",
                    type: 'post',
                    data: {
                        modelid: modelid,
                    },
                    success: function (response){
                        $(".data-list").remove()
                        $.each(response.data.data, function(n,value) {
                            $(".main").append("<div class='data-list' id="+value.id+"></div>")
                            $("#"+value.id).append("<label>" +
                                "<input value="+value.title+" readonly>" +
                                "</label>")
                                .append("<label>" +
                                    "<input readonly value="+value.desc+" >" +
                                    "</label>")
                                .append("<label>" +
                                    "<input readonly value="+value.host+" >" +
                                    "</label>")
                                .append("<label>" +
                                    "<input readonly value="+value.port+" >" +
                                    "</label>")
                                .append("<label>" +
                                    "<select>" +
                                    "<option value="+value.method+">"+value.method+"</option> " +
                                    "</select>" +
                                    "</label>")
                                .append("<label>" +
                                    "<input readonly value="+value.path+" >" +
                                    "</label>")
                                .append("<label>" +
                                    "<input readonly value="+JSON.stringify(value.para)+" >" +
                                    "</label>")
                                .append("<label>" +
                                    "<input readonly value="+JSON.stringify(value.body)+" >" +
                                    "</label>")
                                .append("<label>" +
                                    "<input readonly value="+value.result+" >" +
                                    "</label>")
                                .append("<span class='icon iconfont options edit' title='编辑'>&#xe609;</span>")
                                .append("<span class='icon iconfont options del' title='删除'>&#xe629;</span>")
                                .append("<span class='icon iconfont options dis' title='显示'>&#xe601;</span>")
                            $(".data-list label").css('cssText', "display: inline-block; width: 146.73px;")
                        })
                    }
                })
            }
            else if(stat===201){
                $("div.delete-msg").remove();
                $(".module").css("display", "none");
                $("body").append("<div class='msg'>删除失败！</div>")
                $(".msg").show().delay(1500).fadeOut();
            }
        },
    })
}

function adddiv(id="add"){
    $(".main").append("<div class='view' id="+id+"></div>")
    $(".view").append("<div class='title'><span>名称：</span><input readonly></div>")
    $(".view").append("<div class='title'><span>描述：</span><input readonly></div>")
    $(".view").append("<div class='title'><span>名称：</span><input readonly></div>")
    $(".view").append("<div class='title'><span>名称：</span><input readonly></div>")
    $(".view").append("<div class='title'><span>名称：</span><input readonly></div>")
    $(".view").append("<div class='title'><span>名称：</span><input readonly></div>")
    $(".view").append("<div class='title'><span>名称：</span><input readonly></div>")
    $(".view").append("<div class='title'><span>名称：</span><input readonly></div>")
    $(".view").append("<div class='title'><span>名称：</span><input readonly></div>")
    $(".view").append("<div class='title'><span>名称：</span><input readonly></div>")
    $(".view").append("<div class='title'><span>名称：</span><input readonly></div>")
}